<div align="center" class="grosblanc">Profil de <?php echo $this->session->userdata['prenom']." ".$this->session->userdata['nom'];?></div>

<?php 
echo form_open('administration/monCompte');?>
<div align="center" class="divrondform">
	<table width="1000" border="0" align="center" style="color:#FFF">
  		<tr>
    		<td align="right" width="45%">Nom :&nbsp;</td>
    		<td align="left"><input name="nom" id="nom" type="text" size="30" maxlength="30" value="<?php echo set_value('nom', $this->session->userdata['nom']); ?>"/>&nbsp;<font color="red"><?php echo form_error('nom','* ',' ')?></font></td>
  		</tr>
  		<tr>
    		<td align="right" width="45%">Pr&eacute;nom :&nbsp;</td>
    		<td align="left"><input name="prenom" id="prenom" type="text" size="30" maxlength="30" value="<?php echo set_value('prenom', $this->session->userdata['prenom']); ?>"/>&nbsp;<font color="red"><?php echo form_error('prenom','* ',' ')?></font></td>
  		</tr>
  		<tr>
    		<td align="right" width="45%">Login :&nbsp;</td>
    		<td align="left"><input name="login" id="login" type="text" size="15" maxlength="15" value="<?php echo set_value('login', $this->session->userdata['login']); ?>"/>&nbsp;<font color="red"><?php echo form_error('login','* ',' ')?></font></td>
  		</tr>
  		<tr>
    		<td align="right" width="45%">E-mail :&nbsp;</td>
    		<td align="left"><input name="email" id="email" type="text" size="40" maxlength="64" value="<?php echo set_value('email', $this->session->userdata['email']); ?>"/>&nbsp;<font color="red"><?php echo form_error('email','* ',' ')?></font></td>
  		</tr>
  		<tr>
    		<td align="left"><input name="admin" id="admin" type="hidden" size="1" maxlength="1" value="<?php echo $this->session->userdata['admin']; ?>"/></td>
  		</tr>
  	</table>
  	<br>
	<input class="boutons" name="BMajCompte" type="submit" value="Valider les modifications" style="width:130 px" />
	<input class="boutons" name="BMajCompte" id="BMDP" type="button" value="Modifier le mot de passe" style="width:130 px" />
	<input class="boutons" name="BMajCompte" type="submit" value="Retour" style="width:130 px" />
	<br>
</div>    
</form>

<div id="majmdp-form" title="Modification du mot de passe">
	<?php echo form_open('administration/userMdp', array('id' => 'majmdpform'));?>
    <fieldset>
        <input type="hidden" name="iduser" id="iduser" value="<?php echo $this->session->userdata['id']; ?>"/>
        <input type="hidden" name="mdp" id="mdp" />
        <label for="mdp1" id="l1" class="label-class">Votre nouveau mot de passe</label>
        <input type="password" id="mdp1" size="30" maxlength="30" class="text input-class" />
        <label for="mdp2" id="l2" class="label-class">V&eacute;rification du nouveau mot de passe</label>
        <input type="password" id="mdp2" size="30" maxlength="30" class="text input-class" />
    </fieldset>
    </form>
    <p class="validateTips"></p>
</div>


<script>
$(function() {
	var iduser     = $("#iduser"),
		mdp        = $("#mdp"),
		mdp1       = $("#mdp1"),
		mdp2       = $("#mdp2"),
		allFields  = $([]).add(mdp1).add(mdp2),
		tips       = $(".validateTips"),
		textError  = "";

	$("#BMDP").click(function() {
		allFields.val("").removeClass("ui-state-error");
		updateTips("");
		$("#majmdp-form").dialog("open");
	});
	
	$("#majmdp-form").dialog({
		autoOpen: false,
		height: 'auto',
		width: 900,
		modal: true,
		resizable:false,
		open: function() {
			$("#l1").css('width', '400px');
			$("#l2").css('width', '400px');
		},
		buttons: {
			"Valider": function() {
        		var bValid = 0;
        		allFields.removeClass( "ui-state-error" );
        		textError = "";

        		bValid = checkMdp(mdp1, mdp2, 6, 30 );
	
        		updateTips(textError);
	
				if(bValid == 0) {
					mdp.val(mdp1.val());
					$("#majmdpform").submit();
        			$(this).dialog("close");
				}
     		},
     	
	     	"Fermer": function() {
        		$(this).dialog( "close" );
     		}
		},
	
		close: function() {
			allFields.val( "" ).removeClass( "ui-state-error" );
		},	
	});

	
	function checkMdp( m1, m2, min, max ) { // V�rification des mots de passe : au moins 6 caract�res et identiques
		var retour = 0;
		if(m1.val() == m2.val()) { 
	    	if ( m1.val().length > max || m1.val().length < min ) {
	        	m1.addClass( "ui-state-error" );
	        	if(m1.val().length == 0) { textError = "Vous devez entrer un mot de passe !"; }
	        	else { textError = "Taille du mot de passe entre " + min + " et " + max + "caract\350res."; }
	       		retour = 1;
	    	}
	    	if ( m2.val().length > max || m2.val().length < min ) {
	        	m2.addClass( "ui-state-error" );
	        	if(m2.val().length == 0) { textError = textError + "<br>Vous devez entrer la v�rification du mot de passe !"; }
	        	else { textError = textError + "<br>Taille de mot de passe (2) entre " + min + " et " + max + "caract\350res."; }
	       		retour = 1;
	    	}	    	 
		} else { 
			textError = "Les mots de passe ne sont pas identiques !";
			retour = 1
		}
		return retour;	
	}

	function updateTips( t ) {
	    tips
	    .html( t )
	    .addClass( "petitrouge" );
	}
});
</script>